package com.iee.guava.collections;

import com.google.common.collect.Sets;

import java.util.Set;

public class Test04 {

	public static void main(String[] args) {
		Set<Integer> sets = Sets.newHashSet(1, 2, 3, 4, 5, 6);
		Set<Integer> sets2 = Sets.newHashSet(3, 4, 5, 6, 7, 8, 9);
		// 交集
		System.out.println("交集为：");
		Sets.SetView<Integer> intersection = Sets.intersection(sets, sets2);
		for (Integer temp : intersection) {
			System.out.println(temp);
		}
		// 差集
		System.out.println("差集1为：");
		Sets.SetView<Integer> diff1 = Sets.difference(sets, sets2);
		for (Integer temp : diff1) {
			System.out.println(temp);
		}
		System.out.println("差集2为：");
		Sets.SetView<Integer> diff2 = Sets.difference(sets2,sets);
		for (Integer temp : diff2) {
			System.out.println(temp);
		}
		// 并集
		System.out.println("并集为：");
		Sets.SetView<Integer> union = Sets.union(sets, sets2);
		for (Integer temp : union) {
			System.out.println(temp);
		}
	}

}
